package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

/**
 * @author chy
 * @Description: 公海池规则子枚举类
 * @date 2019/4/2 11:30 AM
 */
@Getter
public enum CustomerRuleChildEnum {
    /**
     * 所有客户统一设置
     */
    ALL(0, "enum.customerRuleChild.name.all"),
    /**
     * 根据客户状态设置
     */
    CUSTOMER_TYPE(1, "enum.customerRuleChild.name.customer_type"),
    /**
     * 根据客户重要程度设置
     */
    IMPORTANT_DEGREE(2, "enum.customerRuleChild.name.important_degree"),

    LABEL(3, "enum.customerRuleChild.name.label"),
    /**
     * 未知类型
     */
    UNKNOWN(404, "enum.customerRuleChild.name.unknown"),
    ;


    /**
     * 枚举值 --
     */
    private final int code;

    /**
     * 枚举信息--中文名称
     */
    private final String name;


    /**
     * 构造一个<code>CustomerRuleChildEnum</code>枚举对象
     *
     * @param code  枚举值
     * @param name  枚举名
     */
    CustomerRuleChildEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }


    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code 枚举值
     * @return PublicCustomerRuleEnum
     */
    public static CustomerRuleChildEnum getByCode(Integer code) {
        for (CustomerRuleChildEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }


}
